package kiwi.assist.dev.guieditor {
	import kiwi.assist.dev.guieditor.command.AddBackgroundCommand;
	import kiwi.assist.dev.guieditor.command.AddNewUi2CanvasCommand;
	import kiwi.assist.dev.guieditor.command.BatchPublishCommand;
	import kiwi.assist.dev.guieditor.command.CloneUiCommand;
	import kiwi.assist.dev.guieditor.command.GuiEditorStartupCommand;
	import kiwi.assist.dev.guieditor.command.GuiEditorStyleChangeCommand;
	import kiwi.assist.dev.guieditor.command.GuiEditorViewBindedCommand;
	import kiwi.assist.dev.guieditor.command.InitCompleteCommand;
	import kiwi.assist.dev.guieditor.command.InitGUIEditorConfigCommand;
	import kiwi.assist.dev.guieditor.command.LoadConfigCommand;
	import kiwi.assist.dev.guieditor.command.LoadUiCommand;
	import kiwi.assist.dev.guieditor.command.MoveUiLayerCommand;
	import kiwi.assist.dev.guieditor.command.NewProjectCommand;
	import kiwi.assist.dev.guieditor.command.PublishAsCommand;
	import kiwi.assist.dev.guieditor.command.PublishJsCommand;
	import kiwi.assist.dev.guieditor.command.RemoveUiCommand;
	import kiwi.assist.dev.guieditor.command.SaveUiCommand;
	import kiwi.assist.dev.guieditor.command.ShowBackgroundSelectDialogCommand;
	import kiwi.assist.dev.guieditor.command.ShowContainerSelectDialogCommand;
	import kiwi.assist.dev.guieditor.command.ShowUiSelectDialogCommand;
	import kiwi.assist.dev.guieditor.command.StartEditorCommand;
	import kiwi.assist.dev.guieditor.command.UiChangeValueCommand;
	import kiwi.assist.dev.guieditor.event.GUIEditorEvent;
	import kiwi.assist.dev.guieditor.event.GUIOperateEvent;
	import kiwi.assist.dev.guieditor.mediator.BackgroundCanvasMediator;
	import kiwi.assist.dev.guieditor.mediator.CanvasMediator;
	import kiwi.assist.dev.guieditor.mediator.GuiEditorMediator;
	import kiwi.assist.dev.guieditor.mediator.GuiEditorMenuMediator;
	import kiwi.assist.dev.guieditor.mediator.PropertyTableMediator;
	import kiwi.assist.dev.guieditor.mediator.SkinCanvasMediator;
	import kiwi.assist.dev.guieditor.mediator.UiListMediator;
	import kiwi.assist.dev.guieditor.model.GUIEditorConfig;
	import kiwi.assist.dev.guieditor.model.UiDetailVO;
	import kiwi.assist.dev.guieditor.view.BackgroundCanvasView;
	import kiwi.assist.dev.guieditor.view.CanvasView;
	import kiwi.assist.dev.guieditor.view.GuiEditorMenu;
	import kiwi.assist.dev.guieditor.view.GuiEditorView;
	import kiwi.assist.dev.guieditor.view.PropertyTable;
	import kiwi.assist.dev.guieditor.view.SkinCanvasView;
	import kiwi.assist.dev.guieditor.view.UiList;

	import org.robotlegs.base.ContextEvent;
	import org.robotlegs.mvcs.Context;

	import flash.display.DisplayObjectContainer;

	/**
	 * @author zhangming.luo
	 */
	public class AppContext extends Context {
		public function AppContext(contextView : DisplayObjectContainer, autoStartup : Boolean = true) {
			super(contextView, autoStartup);
		}

		override public function startup() : void {
			// 全局的配置
			_injector.mapSingleton(GUIEditorConfig);
			// 编辑的ui内容
			_injector.mapSingleton(UiDetailVO);
			_mediatorMap.mapView(GuiEditorView, GuiEditorMediator);
			_mediatorMap.mapView(UiList, UiListMediator);
			_mediatorMap.mapView(PropertyTable, PropertyTableMediator);
			_mediatorMap.mapView(CanvasView, CanvasMediator);
			_mediatorMap.mapView(SkinCanvasView, SkinCanvasMediator);
			_mediatorMap.mapView(BackgroundCanvasView, BackgroundCanvasMediator);
			_mediatorMap.mapView(GuiEditorMenu, GuiEditorMenuMediator);

			_commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, GuiEditorStartupCommand);
			_commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, LoadConfigCommand);
			_commandMap.mapEvent(GUIEditorEvent.INIT_COMPLETE, InitCompleteCommand);
			_commandMap.mapEvent(GUIEditorEvent.NEW_PROJECT, NewProjectCommand);
			_commandMap.mapEvent(GUIEditorEvent.SHOW_CONTAINER_SELECT_DIALOG, ShowContainerSelectDialogCommand);
			_commandMap.mapEvent(GUIEditorEvent.SHOW_BACKGROUND_SELECT_DIALOG, ShowBackgroundSelectDialogCommand);
			_commandMap.mapEvent(GUIEditorEvent.SHOW_UI_SELECT_DIALOG, ShowUiSelectDialogCommand);
			_commandMap.mapEvent(GUIEditorEvent.UI_CREATE, AddNewUi2CanvasCommand);
			_commandMap.mapEvent(GUIEditorEvent.INIT_CONFIG, InitGUIEditorConfigCommand);
			_commandMap.mapEvent(GUIEditorEvent.INIT_GAMECONFIG, InitGUIEditorConfigCommand);
			_commandMap.mapEvent(GUIEditorEvent.STYLE_SELECTION_CHANGE, GuiEditorStyleChangeCommand);
			_commandMap.mapEvent(GUIEditorEvent.VIEW_COMPLETE, GuiEditorViewBindedCommand);
			_commandMap.mapEvent(GUIEditorEvent.LOAD_UIXML, LoadUiCommand);
			_commandMap.mapEvent(GUIEditorEvent.SAVE_UIXML, SaveUiCommand);
			_commandMap.mapEvent(GUIEditorEvent.PUBLISH_AS, PublishAsCommand);
			_commandMap.mapEvent(GUIEditorEvent.PUBLISH_JS, PublishJsCommand);
			_commandMap.mapEvent(GUIEditorEvent.BATCH_PUBLISH, BatchPublishCommand);
			_commandMap.mapEvent(GUIOperateEvent.LAYER_MOVE, MoveUiLayerCommand);
			_commandMap.mapEvent(GUIOperateEvent.CLONE_UI, CloneUiCommand);
			_commandMap.mapEvent(GUIOperateEvent.UI_REMOVE, RemoveUiCommand);
			_commandMap.mapEvent(GUIOperateEvent.BACKGROUND_REMOVE, RemoveUiCommand);
			_commandMap.mapEvent(GUIOperateEvent.BACKGROUND_ADD, AddBackgroundCommand);
			_commandMap.mapEvent(GUIOperateEvent.START_EDIT, StartEditorCommand);
			_commandMap.mapEvent(GUIOperateEvent.CHANGE_VALUE, UiChangeValueCommand);
			super.startup();
		}
	}
}
